export const getJumpUrl = (url) => {
	// let url =
	// 	`https://puhuicaizhi.com/pages/index/login?code=Bjwo3sotw6o6tgQzf1oqBAJbUB3bhcfZAts85NFGhF4&state=STATE#/pages/home/home`
	//`https://puhuicaizhi.com/#/`
	const comIndex = url.indexOf('.com');
	if (comIndex === -1) {
		return {
			extractedPart: '',
			hasValueAfterDomain: false
		};
	}

	// 从".com"之后的位置开始截取
	const startIndex = comIndex + 4; // 4是".com"的长度
	const questionIndex = url.indexOf('?', startIndex);

	let extractedPart;
	if (questionIndex !== -1) {
		// 截取从.com后到?之前的部分
		extractedPart = url.substring(startIndex, questionIndex);
	} else {
		// 如果没有?，则截取从.com后到结尾（但要排除可能的#及后面内容）
		const hashIndex = url.indexOf('#', startIndex);
		if (hashIndex !== -1) {
			extractedPart = url.substring(startIndex, hashIndex);
		} else {
			extractedPart = url.substring(startIndex);
		}
	}

	// 判断域名后面是否有值（即提取的部分是否非空）
	const hasValueAfterDomain = extractedPart.trim() !== '';
	console.log('extractedPart', extractedPart, hasValueAfterDomain)
	if (extractedPart != '/pages/index/callBack') {
		if (hasValueAfterDomain) {
			if (extractedPart == '/') {
				uni.setStorageSync('jumpUrl', '/pages/home/home');
			} else {
				uni.setStorageSync('jumpUrl', extractedPart);
			}

		} else {
			uni.setStorageSync('jumpUrl', '/pages/home/home');
		}
	}


	// setTimeout(() => {
	// 	const encodedTarget = encodeURIComponent('/pages/index/callBack');
	// 	const authUrl =
	// 		`https://puhuicaizhi.com/wx/yingyong/login?wantUrl=${encodedTarget}`;
	// 	console.log('authUrl', authUrl);
	// 	window.location.href = authUrl
	// }, 500)


}

// export default getJumpUrl

// // 测试示例
// const url1 = 'https://puhuicaizhi.com/pages/index/login?code=Bjwo3sotw6o6tgQzf1oqBAJbUB3bhcfZAts85NFGhF4&state=STATE#/pages/home/home';
// const url2 = 'https://puhuicaizhi.com/?code=Bjwo3sotw6o6tgQzf1oqBAJbUB3bhcfZAts85NFGhF4&state=STATE#/pages/home/home';
// const url3 = 'https://puhuicaizhi.com#/pages/home/home';
// const url4 = 'https://puhuicaizhi.com';

// console.log(extractPartBetweenComAndQuestion(url1)); 
// // 输出: { extractedPart: "/pages/index/login", hasValueAfterDomain: true }

// console.log(extractPartBetweenComAndQuestion(url2)); 
// // 输出: { extractedPart: "/", hasValueAfterDomain: true }

// console.log(extractPartBetweenComAndQuestion(url3)); 
// // 输出: { extractedPart: "", hasValueAfterDomain: false }

// console.log(extractPartBetweenComAndQuestion(url4)); 
// // 输出: { extractedPart: "", hasValueAfterDomain: false }